// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.core.skinnedmodel.animation;

import java.util.ArrayList;
import java.util.List;

public final class AnimationMultiTrack {
    private final ArrayList<AnimationTrack> m_tracks = new ArrayList();
    private static final ArrayList<AnimationTrack> tempTracks = new ArrayList();

    public AnimationTrack findTrack(String trackName) {
        int int0 = 0;

        for (int int1 = this.m_tracks.size(); int0 < int1; int0++) {
            AnimationTrack animationTrack = (AnimationTrack)this.m_tracks.get(int0);
            if (animationTrack.name.equals(trackName)) {
                return animationTrack;
            }
        }

        return null;
    }

    public void addTrack(AnimationTrack track) {
        this.m_tracks.add(track);
    }

    public void removeTrack(AnimationTrack track) {
        int _int = this.getIndexOfTrack(track);
        if (_int > -1) {
            this.removeTrackAt(_int);
        }
    }

    public void removeTracks(List<AnimationTrack> tracks) {
        tempTracks.clear();
        tempTracks.addAll(tracks);

        for (int _int = 0; _int < tempTracks.size(); _int++) {
            this.removeTrack((AnimationTrack)tempTracks.get(_int));
        }
    }

    public void removeTrackAt(int indexOf) {
        ((AnimationTrack)this.m_tracks.remove(indexOf)).release();
    }

    public int getIndexOfTrack(AnimationTrack track) {
        if (track == null) {
            return -1;
        } else {
            int int0 = -1;

            for (int int1 = 0; int1 < this.m_tracks.size(); int1++) {
                AnimationTrack animationTrack = (AnimationTrack)this.m_tracks.get(int1);
                if (animationTrack == track) {
                    int0 = int1;
                    break;
                }
            }

            return int0;
        }
    }

    public void Update(float time) {
        for (int _int = 0; _int < this.m_tracks.size(); _int++) {
            AnimationTrack animationTrack = (AnimationTrack)this.m_tracks.get(_int);
            animationTrack.Update(time);
            if (animationTrack.CurrentClip == null) {
                this.removeTrackAt(_int);
                _int--;
            }
        }
    }

    public float getDuration() {
        float float0 = 0.0F;

        for (int _int = 0; _int < this.m_tracks.size(); _int++) {
            AnimationTrack animationTrack = (AnimationTrack)this.m_tracks.get(_int);
            float float1 = animationTrack.getDuration();
            if (animationTrack.CurrentClip != null && float1 > float0) {
                float0 = float1;
            }
        }

        return float0;
    }

    public void reset() {
        int int0 = 0;

        for (int int1 = this.m_tracks.size(); int0 < int1; int0++) {
            AnimationTrack animationTrack = (AnimationTrack)this.m_tracks.get(int0);
            animationTrack.reset();
        }

        AnimationPlayer.releaseTracks(this.m_tracks);
        this.m_tracks.clear();
    }

    public List<AnimationTrack> getTracks() {
        return this.m_tracks;
    }

    public int getTrackCount() {
        return this.m_tracks.size();
    }

    public AnimationTrack getTrackAt(int i) {
        return (AnimationTrack)this.m_tracks.get(i);
    }
}
